// 771. 宝石与石头
class Solution {
public:
    int numJewelsInStones(string jewels, string stones) {
        unordered_map<char, int> map;
        for(char e : stones) map[e]++;
        int ret = 0;
        for(char e : jewels) ret += map[e];
        return ret;
    }
};

// 202. 快乐数
class Solution {
public:
    int bitSum(int n)
    {
        int ret = 0;
        while(n)
        {
            int tmp = n % 10;
            ret += tmp*tmp;
            n /= 10;
        }
        return ret;
    }

    bool isHappy(int n) 
    {
        int slow = n, fast = bitSum(n);
        while(slow != fast)
        {
            slow = bitSum(slow);
            fast = bitSum(bitSum(fast));
        }
        return slow == 1;
    }
};